<#include "/common/head.html"/>    
<div id="zcurdHeadTable" class="easyui-panel" data-options="fit:true,border:false,novalidate:true">
    <div style="padding:0px">
    <form class="easyui-form" id="ff" method="post" data-options="novalidate:true">
        <table cellpadding="9" width="100%" style="margin-top:20px ">
            <tr>
           		<th><span>旧密码：</span></th>
               	<td>
               			<input class="easyui-validatebox" type="password"  required="true" name="old_password" value="" data-options="" style="width: 130px;"></input>
           		</td>
           	</tr>
            <tr>
           		<th><span>新密码：</span></th>
               	<td>
               			<input class="easyui-validatebox" type="password"  required="true" name="password" value="" data-options="" style="width: 130px;"></input>
           		</td>
           	</tr>
            <tr>
           		<th><span>确认密码：</span></th>
               	<td>
               			<input class="easyui-validatebox" type="password"   required="true"  name="surepassword" value="" data-options="" style="width: 130px;"></input>
           		</td>
           		
            </tr>
            <tr>
            	<th></th>
            	<td><span style="color: red;">*密码必须是长度为6-16个字符</span></td>
            </tr>
        </table>
        
    </form>
    </div>
</div>
<script>
top.window.subPage.save = save;
function save() {
	var old_password = $.trim($(":input[name='old_password']").val());
	var password = $.trim($(":input[name='password']").val());
	var surepassword = $.trim($(":input[name='surepassword']").val());
	if($("#ff").form('enableValidation').form('validate')) {
		if (old_password.length == 0){
			showMsg("请输入旧密码！");
			return ;
		}
		if (old_password == password){
			showMsg("新旧密码一样，请重新输入！");
			return ;
		}
		if(password.length < 6 || password.length > 16){
			toEmpty();
			showMsg("新密码长度不符合规范，请重新输入！");
			return;
		}
		if(password != surepassword){
			toEmpty();
			showMsg("两次密码输入不一致，请重新输入！");
			return;
		}
		$.post("changePwd", getParam(), function(data) {
			if (data.result=="success"){
				top.window.location.href=basePath+"/login/logout";
			} 
			top.window.closeWindow();
		});
	}
}
function toEmpty(){
	$(":input[name='password']").val("");
	$(":input[name='surepassword']").val("");
}
function getParam() {
	var param = {
   	    "model.id": ${model.id},
   	 	"model.old_password": $(":input[name='old_password']").val(),
   		"model.password": $(":input[name='password']").val()
	}
	for(key in param) {
		if(!param[key]) {
			delete param[key];
		}
	}
	return param;
}

</script>